import { request } from '../utils/request';
import { Priority, TaskStatus, ProjectStatus } from '../types/enums';
import {
  ApiResponse,
  PaginatedResponse,
  Workspace,
  WorkspaceMember,
  Project,
  Task,
  Notification
} from '../types/api';

// 仪表板API
export const dashboardAPI = {
  // 获取我的工作区
  async getMyWorkspaces(): Promise<ApiResponse<Workspace[]>> {
    return request.get('/workspaces/my');
  },

  // 获取项目列表
  async getProjects(params?: { workspaceId?: string; status?: ProjectStatus }): Promise<ApiResponse<Project[]>> {
    return request.get('/projects', { params });
  },

  // 获取任务列表
  async getTasks(params?: {
    projectId?: string;
    status?: TaskStatus;
    priority?: Priority;
    assigneeId?: string;
  }): Promise<ApiResponse<Task[]>> {
    return request.get('/tasks', { params });
  },

  // 更新任务状态
  async updateTaskStatus(taskId: string, status: TaskStatus): Promise<ApiResponse<void>> {
    return request.patch(`/tasks/${taskId}`, { status });
  },

  // 获取通知列表
  async getNotifications(params?: {
    page?: number;
    limit?: number;
    isRead?: boolean;
  }): Promise<ApiResponse<PaginatedResponse<Notification>>> {
    return request.get('/notifications', { params });
  },

  // 获取未读通知数量
  async getUnreadNotificationCount(): Promise<ApiResponse<{ count: number }>> {
    return request.get('/notifications/unread-count');
  },

  // 获取工作区成员
  async getWorkspaceMembers(workspaceId: string): Promise<ApiResponse<WorkspaceMember[]>> {
    return request.get(`/workspaces/${workspaceId}/members`);
  }
}; 